﻿using BarManager.Core.BusinessRules.Interfaces.Specification;
using BarManager.Core.DomainService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Entity = BarManager.Core.Entity;

namespace BarManager.Core.BusinessRules.Specification
{
    public class MesaEstaLibre: BaseSpecification<Entity.Orden>, IOrdenSpecification
    {        
        private IMesaRepository MesaRepository { get; set; }
        private bool MesaLibre { get; set; }

        public MesaEstaLibre(IOrdenRepository repository, IMesaRepository mesaRepository)
            : base(repository)
        {
            this.MesaRepository = mesaRepository;
            MesaLibre = false;
        }

        public override bool IsSatisfiedBy(Entity.Orden entity)
        {
            MesaLibre = MesaRepository.Get(x => x.Id == entity.MesaId).Libre;
            return MesaLibre;
        }

        public override IEnumerable<string> GetErrorMessage()
        {
            if (!MesaLibre) yield return "La Mesa seleccionada se encuentra ocupada";
            yield break;
        }
    }
}
